package com.fenghuajueli.lib_pictureselect.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.fenghuajueli.lib_pictureselect.R;

public class ProgressDialog extends Dialog {

    private TextView tvCurrentProgress;

    public ProgressDialog(@NonNull Context context) {
        super(context, R.style.StyleBaseDialog);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.progress_dialog_layout);
        tvCurrentProgress = findViewById(R.id.tvCurrentProgress);
    }


    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(layoutParams);
    }

    /**
     * 显示进度
     *
     * @param progress
     * @param currentCount
     * @param allCount
     */
    public void setProgress(int progress, int currentCount, int allCount) {
        if (tvCurrentProgress.getVisibility() == View.INVISIBLE) {
            tvCurrentProgress.setVisibility(View.VISIBLE);
        }
        if (isShowing()) {
            tvCurrentProgress.setText(getContext().getString(R.string.video_make_progress, progress, currentCount, allCount));
        }
    }

    /**
     * 显示进度
     *
     * @param progress
     */
    public void setExportProgress(int progress) {
        if (tvCurrentProgress.getVisibility() == View.INVISIBLE) {
            tvCurrentProgress.setVisibility(View.VISIBLE);
        }
        if (isShowing()) {
            tvCurrentProgress.setText(getContext().getString(R.string.video_export_progress, progress+"%"));
        }
    }
}
